using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Xml;
using Northwoods.Go;
using Northwoods.Go.Xml;

namespace Workflows.Diagrams
{
    [Serializable()]
    public class TransformActivityPort : GoXmlTransformer
    {
        public TransformActivityPort()
        {
            this.TransformerType = typeof(ActivityPort);
            this.ElementName = "port";
            this.IdAttributeUsedForSharedObjects = true;
        }

        public override void GenerateAttributes(object obj)
        {
            base.GenerateAttributes(obj);
            ActivityPort p = (ActivityPort)obj;
            this.WriteAttrVal("userFlags", p.UserFlags);
            if (p.MaxLinks != 999999)
                this.WriteAttrVal("maxLinks", p.MaxLinks);
            this.WriteAttrVal("xy", p.Position);
            this.WriteAttrVal("spot", p.FromSpot);
        }

        public override void ConsumeAttributes(object obj)
        {
            base.ConsumeAttributes(obj);
            ActivityPort p = (ActivityPort)obj;
            p.UserFlags = Int32Attr("userFlags", p.UserFlags);
            if (this.IsAttrPresent("maxLinks"))
                p.MaxLinks = Int32Attr("maxLinks", p.MaxLinks);
            p.Position = PointFAttr("xy", new PointF(10, 10));
            int spot = Int32Attr("spot", -1);
            if (spot > -1)
            {
                p.FromSpot = spot;
                p.ToSpot = spot;
            }
        }
    }
}
